﻿using System;
using MongoDB.Driver;
using Sustainalytics.ClientDW.Entities;
using Sustainalytics.Synchronization.Validation.Handlers.Common;
using Sustainalytics.Synchronization.Validation.Internals;
using Sustainalytics.Synchronization.Validation.Validators;

namespace Sustainalytics.Synchronization.Validation.Handlers.Events
{
    public class EventIndicatorHandler : Handler<EventIndicator, ControversyCompanies>
    {
        public EventIndicatorHandler(ControversyCompanies controversyCompanies, ValidationMongoCollection<EventIndicator> collections, EventsValidator<EventIndicator> validator)
            : base(controversyCompanies, collections, validator)
        {
        }

        protected override ProjectionDefinition<EventIndicator> GetProjectionDefinition()
        {
            return
                Builders<EventIndicator>.Projection
                    .Include(x => x.Id)
                    .Include(x => x.CompanyId)
                    .Include(x => x.Name)
                    .Include(x => x.AnswerCategory)
                    .Include(x => x.BaseEventIndicatorId)
                    .Include(x => x.ControversyIndicatorName)
                    .Include(x => x.ControversyIndicatorNumber);
        }

        protected override FilterDefinition<EventIndicator> GetReferenceEntityFilter(EventIndicator validatedEntity)
        {
            return Builders<EventIndicator>.Filter
                .Where(x => x.CompanyId == validatedEntity.CompanyId && x.BaseEventIndicatorId == validatedEntity.BaseEventIndicatorId);
        }

        protected override FilterDefinition<EventIndicator> GetValidatedEntityFilterDefinition(Guid companyId)
        {
            return Builders<EventIndicator>.Filter.Where(x => x.CompanyId == companyId);
        }
    }
}
